from sklearn.datasets import load_digits
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('TkAgg')

test_data = load_digits()
x = test_data['data']
y = test_data['target']

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42)
tree_entropy = DecisionTreeClassifier(criterion='entropy', random_state=42)
tree0 = DecisionTreeClassifier(random_state=42)
tree_entropy.fit(x_train, y_train)
tree0.fit(x_train, y_train)

# 评价模型
tree_entropy_score = tree_entropy.score(x_test, y_test)
tree0_score = tree0.score(x_test, y_test)
print("tree_entropy_score:", tree_entropy_score)
print("tree0_score:", tree0_score)